package com.lframework.xingyun.api.controller.opFile;

import com.lframework.xingyun.basedata.vo.common.RequestBase;
import com.lframework.xingyun.sc.util.MinioUtil;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDateTime;

import static org.aspectj.weaver.tools.cache.SimpleCacheFactory.path;

/**
 * @author zhoujh
 * @Description 测试文件操作
 * @Date 2022/8/26 11:12
 */
@Api(tags = "文件测试")
@Validated
@RestController
@RequestMapping("/test/file")
@Slf4j
public class TestFileController {
    @Resource
    private MinioUtil minioUtil;

    @GetMapping("/bucket")
    public String createBucket(String name) {
        log.info("创建桶：{}, name :{}", LocalDateTime.now(), name);
        boolean flag = minioUtil.createBucket(name);
        return name + flag;
    }

    @PostMapping("/uploadFile")
    public String uploadFile(@RequestBody RequestBase requestBase) throws Exception{
        log.info("uploadFile：{}, name :{}", LocalDateTime.now(), requestBase.getBucket());
        String remote_url = minioUtil.uploadFile(requestBase.getBucket(), requestBase.getPath());
        log.info("上传结束：文件名：{}", remote_url);
        return remote_url;
    }
}
